package com.letv.so.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class BaseServlet extends HttpServlet {

	private static final long serialVersionUID = -6337385994431004541L;

	private static final Logger logger = Logger.getLogger(BaseServlet.class);

	protected WebApplicationContext wac;

	public void init() throws ServletException {
		wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		logger.info("BaseServlet_init");
	}

	public void printNoCache(HttpServletResponse response, String result) {
		try {
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
			byte[] data = result.getBytes(response.getCharacterEncoding());
			response.setContentLength(data.length);
			response.getOutputStream().write(data, 0, data.length);
		} catch (IOException e) {
			logger.error("print result error!", e);
		}
	}
}
